﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;
using System.IO;

public partial class en_ucControl_ManagerPhotos : System.Web.UI.UserControl
{
    TblAlbumImagesDAO AlbumDAO = new TblAlbumImagesDAO(Global.CONNECTION_STRING);
    TblImagesDAO ImageDAO = new TblImagesDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session[Global.SESSION_LOGGED_USER] != null)
            {
                LoadImagebyIDAcc();
            }
            else
                Response.Redirect("~/en/Default.aspx");
        }
    }
    

    private void LoadImagebyIDAcc()
    {
        int IDAcc = ((TblAccounts)Session[Global.SESSION_LOGGED_USER]).IDAcc;

        DataTable dt = AlbumDAO.GetAlbumsByIDAcc(IDAcc);
        grdImageByIDAcc.DataSource = dt;
        grdImageByIDAcc.DataBind();
        string IDAlbum = "";
        foreach (DataRow dr in dt.Rows)
        {
            IDAlbum = dr["IDAlbum"].ToString();
        }
        if (IDAlbum == "" || IDAlbum == null)
        {
            Response.Redirect("~/en/Upload.aspx");
        }
        else
        {
            DataTable dt1 = ImageDAO.GetImageByIdAlbum(Convert.ToInt32(IDAlbum));
            reImageByAlbum.DataSource = dt1;
            reImageByAlbum.DataBind();

            foreach (DataRow dr1 in dt.Rows)
            {
                lblAlbumName.Text = dr1["AlbumName"].ToString();
            }
        }
        hypGetPhotoGroup.NavigateUrl = "~/en/GetCodePhotosGroups.aspx?IdAl=" + IDAlbum + "&keepThis=true&TB_iframe=true&width=700&height=450&ico=images/Get.png";
    }
    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        int IdAl = Convert.ToInt32(((ImageButton)sender).CommandArgument);
        Response.Redirect("~/en/Upload.aspx?IdAl=" + IdAl);
    }

    protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
    {
    }

    protected void grdImageByIDAcc_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (DataControlFieldCell cell in e.Row.Cells)
            {
                // check all cells in one row
                foreach (Control control in cell.Controls)
                {
                    ImageButton button = control as ImageButton;
                    if (button != null && button.CommandName == "Delete")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Do you want delete this Photo?')) return false;";
                    }
                    if (button != null && button.CommandName == "Save")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Bạn có muốn lưu không?')) return false;";
                    }
                }
            }
        }
    }
}
